﻿using System.Configuration;
using System.ServiceModel;
using System.ServiceModel.Security;
using BlueMarineWebClient.BlueMarineService;

namespace BlueMarineWebClient.DO
{
    public static class ServiceBool
    {
        private static ExternalServiceClient _exService = new ExternalServiceClient("WSHttpBinding_IExternalService")
                                                              {
                                                                  ClientCredentials =
                                                                      {
                                                                          UserName =
                                                                              {
                                                                                  Password =
                                                                                      ConfigurationManager.AppSettings[1
                                                                                      ],
                                                                                  UserName =
                                                                                      ConfigurationManager.AppSettings[0
                                                                                      ]
                                                                              },
                                                                          ServiceCertificate =
                                                                              {
                                                                                  Authentication =
                                                                                      {
                                                                                          CertificateValidationMode =
                                                                                              X509CertificateValidationMode
                                                                                              .None
                                                                                      }
                                                                              }
                                                                      }
                                                              };

        public static ExternalServiceClient ExService
        {
            get
            {
                if (_exService.State == CommunicationState.Faulted)
                {
                    _exService.Abort();
                    _exService = new ExternalServiceClient("WSHttpBinding_IExternalService")
                                     {
                                         ClientCredentials =
                                             {
                                                 UserName =
                                                     {
                                                         Password = ConfigurationManager.AppSettings[1],
                                                         UserName = ConfigurationManager.AppSettings[0]
                                                     },
                                                 ServiceCertificate =
                                                     {
                                                         Authentication =
                                                             {
                                                                 CertificateValidationMode =
                                                                     X509CertificateValidationMode.None
                                                             }
                                                     }
                                             }
                                     };
                }
                return _exService;
            }
        }
    }
}